package com.xiaoxin.project.system.service.impl;


import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.xiaoxin.framework.aspectj.lang.annotation.DataSource;
import com.xiaoxin.framework.aspectj.lang.enums.DataSourceType;
import com.xiaoxin.project.system.domain.SysOrder;
import com.xiaoxin.project.system.mapper.SysOrderMapper;
import com.xiaoxin.project.system.service.SysOrderService;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

/**
 * 订单Service业务层处理
 *
 * @author ZhangXX
 */
@Service
public class SysOrderServiceImpl extends ServiceImpl<SysOrderMapper, SysOrder> implements SysOrderService {

    /**
     * 查询订单
     *
     * @param orderId 订单编号
     * @return 订单信息
     */
    @Override
    @DataSource(DataSourceType.SHARDING)
    public SysOrder selectSysOrderById(Long orderId) {
        return baseMapper.selectSysOrderById(orderId);
    }

    /**
     * 查询订单列表
     *
     * @param sysOrder 订单信息
     * @return 订单列表
     */
    @Override
    @DataSource(DataSourceType.SHARDING)
    public List<SysOrder> selectSysOrderList(SysOrder sysOrder) {
        return baseMapper.selectSysOrderList(sysOrder);
    }

    /**
     * 新增订单
     *
     * @param sysOrder 订单
     * @return 结果
     */
    @Override
    @DataSource(DataSourceType.SHARDING)
    //@Transactional
    public int insertSysOrder(SysOrder sysOrder) {
        baseMapper.insertSysOrder(sysOrder);
        //int i = 1 / 0;
        return 1;
    }

    @Override
    @DataSource(DataSourceType.SHARDING)
    public List<SysOrder> selectSysOrderByUserId(Long startUserId, Long endUserId) {
        return baseMapper.selectSysOrderByUserId(startUserId, endUserId);
    }
}
